<?php
include("./include/config.inc.php");
include("./imageFunc.php");
if(isset($_POST['submitBtn']))
{
	$insert = "INSERT INTO slider (menuId,sliderImg) 
	                 VALUE (".$_POST['menuId'].",'".$_FILES['imageUpload']['name']."')";
  $insertRes = mysql_query($insert);
  $lastDesignMasterId = mysql_insert_id();
    
  if(isset($_FILES["imageUpload"]["name"]))
 	{
 	  //Image Upload Code Start::://
		if ((($_FILES["imageUpload"]["type"] == "image/gif")
	  || ($_FILES["imageUpload"]["type"] == "image/jpeg")
	  || ($_FILES["imageUpload"]["type"] == "image/pjpeg")
	  || ($_FILES["imageUpload"]["type"] == "image/png")
	  || ($_FILES["imageUpload"]["type"] == "image/bmp")))
	  {
	  	//$rand = rand(1,999);
			$filename  =  pathinfo($_FILES["imageUpload"]["name"]);
			$extension = $filename['extension'];
			$image = "sliderImg_".$lastDesignMasterId.".".$extension;
			$file = "sliderImage/".$image; 
			if (move_uploaded_file($_FILES['imageUpload']['tmp_name'], $file)) 
			{ 
			  $imageParameter = array(); 
				$thumbnail = new thumbnail();
				//get image size
				list($width, $height) = getimagesize($file);
				// Create Thubnail::::
				if(($width > $cfgThumbnailWidth) || ($height > $cfgThumbnailHeight))
				{
				  $imageParameter = setImageHightWigth($height,$width,$cfgThumbnailWidth,$cfgThumbnailHeight);
				  $thumbnail->generate("sliderImage/".$image,$image,"sliderImage/thumb/",$image,$imageParameter['newWidth'], $imageParameter['newHeight']);
				}
				else
				  @copy("sliderImage/".$image,"sliderImage/thumb/".$image);
				// Create Thubnail End::::
			} 
			else 
			{
				echo "error";
			}
		}
	}
	$updateImage = "UPDATE slider
                     SET sliderImg = '".$image."'
                   WHERE sliderId  = ".$lastDesignMasterId;
  $updateImageRes = mysql_query($updateImage);
  //header("Location:slider.php");
}
$menuArray = array();
$i = 0;
$selectMenu = "SELECT menuId,menuName
                 FROM menu";
$selectMenuRes = mysql_query($selectMenu);
while($menuRow = mysql_fetch_array($selectMenuRes))
{
  $menuArray['menuId'][$i]   = $menuRow['menuId'];
  $menuArray['menuName'][$i] = $menuRow['menuName'];
  $i++;
}

$smarty->assign("menuArray",$menuArray);
$smarty->display("slider.tpl");
?>